<extend name="Layout:ly1"/>

<block name="head">
    <script>
        jQuery(document).ready(function($) {
            $(".opt_admin_user_group").hide();
            var Table = $("table");
            var DataTable = Table.DataTable({
                language: dataTables_zh_CN,
                pageLength: 100
            });
            //添加用户组
            $("#add_group").click(function(event) {
                $("input[name='operate']").val('add_group');
                $(".opt_admin_user_group").show();
                $("input[name='id']").val('').parents('.form-group').hide();
                $("input[name=status]").last().trigger('click');
            });
            //编辑用户组
            $(".group_edit").click(function(){
                var tr = $(this).closest('tr');
                $("input[name='id']").val(tr.data('id')).parents('.form-group').show();
                $("input[name='operate']").val('edit_group');
                $("input[name='title']").val(tr.data('title'));
                $("input[name=status][value='" + tr.data('status') + "']").trigger('click');
                $(".opt_admin_user_group").show();
            });
            //用户组提交
            $("#group_submit").click(function(event) {
                $("form#opt_group_form").ajaxSubmit({
                    success:function(msg){
                        if(msg==1){
                            location.reload();
                        }else{
                            alert(msg);
                        }
                    }
                });
            });
            //表单取消
            $("#group_cancel").click(function(){
                $(".opt_admin_user_group").hide();
            });
            //删除用户组
            $(".group_delete").click(function(){
                if(confirm("确认删除?")){
                    var tr = $(this).closest('tr');
                    $.ajax({
                        url:"{:U('Admin/User/group_manage')}",
                        type:"POST",
                        data:{operate:'delete_group',group_id:tr.data("id")},
                        success:function(msg){
                            if(msg==1){
                                location.reload();
                            }else{
                                alert("删除失败");
                            }
                        }
                    });
                }
            });
        });
    </script>
</block>

<block name="body">
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">用户组管理</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        用户组列表
                        <span class="pull-right"><a id="add_group">添加用户组</a></span>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="opt_admin_user_group">
                            <form id="opt_group_form" class="form-horizontal overflow_hidden" method="post" action="{:U('Admin/User/group_manage')}">
                                <input type="hidden" name="operate">
                                <div class="form-group">
                                    <label for="id" class="col-sm-2 control-label">编号</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="id" id="id" readonly>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="title" class="col-sm-2 control-label">标题</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="title" id="title" placeholder="标题">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-sm-8">
                                        <input type="radio" name="status" value="0"> 禁用
                                        <input type="radio" name="status" value="1"> 启用
                                    </div>
                                </div>
                            </form>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-8">
                                    <a class="btn btn-success" id="group_submit">确认</a>
                                    <a class="btn btn-warning" id="group_cancel">取消</a>
                                </div>
                            </div>
                        </div>
                        <div class="dataTable_wrapper">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>标题</th>
                                    <th>状态</th>
                                    <th>添加时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach($group_list as $k => $v): ?>
                                <tr data-id="{$v['id']}" data-title="{$v['title']}" data-status="{$v['status']}">
                                    <td scope="row">{$v['id']}</td>
                                    <td>{$v['title']}</td>
                                    <td>{$v['status_name']}</td>
                                    <td>{:date("Y-m-d H:i",$v['create_time'])}</td>
                                    <td>
                                        <button class="btn btn-warning group_edit">编辑</button>
                                        <button class="btn btn-danger group_delete">删除</button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
    </div>
    <!-- /#page-wrapper -->
</block>